<?php
if (!isset($_GET['ok'])) {
        exit('Error');
}
@header("Content-Type:text/html;charset=utf-8");
$startime = time();
set_time_limit(0);
include_once  dirname(dirname(__FILE__)) . '/nn_logic/nl_common.func.php';
include_once "nncms_controls_pinyin_class.php";
$dc = nl_get_dc(array(
    'db_policy' => NL_DB_WRITE,
    'cache_policy' => NP_KV_CACHE_TYPE_MEMCACHE
        )
);
$livecout = 0;
$vodcout = 0;
$mzbcout = 0;
$pcout = 0;
//连接数据库
$dc->open();
$db = $dc->db();
$vodsql = "SELECT *
FROM (
SELECT  `nns_id`,`nns_name` ,CHAR_LENGTH(  `nns_name` ) AS name,  `nns_pinyin_length` 
FROM  `nns_vod`
) AS se
WHERE name !=  `nns_pinyin_length`";



$vod = nl_query_by_db($vodsql, $db); //点播视频
if (!is_array($vod))
        $vod = array();
foreach ($vod as $v) {
        $py = @nns_controls_pinyin_class::get_pinyin_letter($v['nns_name']);
        if (empty($py))
                continue;
        $length = @nns_controls_pinyin_class::$length;
        $vodupsql = "UPDATE  `nns_vod` SET  `nns_pinyin`=  '$py',`nns_pinyin_length`='$length'  WHERE  `nns_id` =  '{$v['nns_id']}'";
        nl_execute_by_db($vodupsql, $db);
        $vodcout++;
        $return = mzb($v['nns_id'], $py, $length); //更换媒资包的拼音
        if ($return)
                $mzbcout++;
        //echo count($vod) - $vodcout . "VOD<br/>";
}
$livesql = "SELECT *
FROM (
SELECT  `nns_id`,`nns_name` ,CHAR_LENGTH(  `nns_name` ) AS name,  `nns_pinyin_length` 
FROM  `nns_live`
) AS se
WHERE name !=  `nns_pinyin_length`";
$live = nl_query_by_db($livesql, $db); //点播视频
if (!is_array($live))
        $live = array();
foreach ($live as $l) {
        $py = @nns_controls_pinyin_class::get_pinyin_letter($l['nns_name']);
        if (empty($py))
                continue;
        $length = @nns_controls_pinyin_class::$length;
        $vodupsql = "UPDATE  `nns_live` SET  `nns_pinyin` =  '$py',`nns_pinyin_length`='$length' WHERE  `nns_id` =  '{$l['nns_id']}'";
        nl_execute_by_db($vodupsql, $db);
        $livecout++;
        $return = mzb($l['nns_id'], $py, $length); //更换媒资包的拼音
        if ($return)
                $mzbcout++;
        //echo count($live) - $livecout . "LIVE<br/>";
}

$psql = "SELECT *
FROM (
SELECT  `nns_id`,`nns_name` ,CHAR_LENGTH(  `nns_name` ) AS name,  `nns_pinyin_length` 
FROM  `nns_live_playbill_item`
) AS se
WHERE name !=  `nns_pinyin_length`";
$plive = nl_query_by_db($psql, $db); //点播视频
if (!is_array($plive))
        $plive = array();
foreach ($plive as $p) {
        $py = @nns_controls_pinyin_class::get_pinyin_letter($p['nns_name']);
        if (empty($py))
                continue;
        $length = @nns_controls_pinyin_class::$length;
        $pupsql = "UPDATE  `nns_live_playbill_item` SET  `nns_pinyin` =  '$py',`nns_pinyin_length`='$length' WHERE  `nns_id` =  '{$p['nns_id']}'";
        nl_execute_by_db($pupsql, $db);
        $pcout++;
        //echo count($plive) - $pcout . "PLIVE<br/>";
}

if ($_GET['ok'] != 'no') {
        $time = time() - $startime;
        var_dump("直播：$livecout,点播：$vodcout,媒资包：$mzbcout,节目单：$pcout,耗时：$time 秒");
}

function mzb($id, $py, $length) {
        global $db;
        if (empty($id) || empty($py))
                return false;
        $sql = "UPDATE `nns_assists_item` SET  `nns_pinyin` =  '$py',`nns_pinyin_length`='$length' WHERE  `nns_video_id` =  '$id'";
        $result = nl_execute_by_db($sql, $db);
        return $result;
}

?>